package com.zlp.mall.portal.controller;


import com.zlp.mall.common.api.R;
import com.zlp.mall.portal.modules.ums.dto.req.MemberReceiveAddressAddReq;
import com.zlp.mall.portal.modules.ums.dto.req.MemberReceiveAddressUpdReq;
import com.zlp.mall.portal.modules.ums.model.MemberReceiveAddress;
import com.zlp.mall.portal.modules.ums.service.MemberReceiveAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author ZouLiPing
 * @since 2021-10-15
 */
@RestController
@RequiredArgsConstructor
@Api(value = "MemberReceiveAddressController", tags = "前台会员地址管理")
@RequestMapping("/member/address")
public class MemberReceiveAddressController {

    private final MemberReceiveAddressService memberReceiveAddressService;


    @GetMapping(value = "/list")
    @ApiOperation(value = "获取地址信息")
    public R<List<MemberReceiveAddress>> list() {

        return R.success(memberReceiveAddressService.listByMemberId());
    }

    @PostMapping(value = "/update/{id}")
    @ApiOperation(value = "修改")
    public R update(@PathVariable Long id,@Valid @RequestBody MemberReceiveAddressUpdReq memberReceiveAddressUpdReq) {

        return R.success(memberReceiveAddressService.update(id,memberReceiveAddressUpdReq));
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "添加")
    public R add(@Valid @RequestBody MemberReceiveAddressAddReq memberReceiveAddressAddReq) {

        return R.success(memberReceiveAddressService.add(memberReceiveAddressAddReq));
    }

    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除")
    public R delete(@PathVariable Long id) {

        return R.success(memberReceiveAddressService.delete(id));
    }



}

